package me.work.pay.jsyl.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.google.gson.Gson;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.yzy.voice.VoicePlay;

import butterknife.BindView;
import me.work.pay.jsyl.R;
import me.work.pay.jsyl.app.Constants;
import me.work.pay.jsyl.mvp.contract.PayResultContract;
import me.work.pay.jsyl.mvp.model.AppModel;
import me.work.pay.jsyl.mvp.model.entity.Order;
import me.work.pay.jsyl.mvp.presenter.PayResultPresenter;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 09/15/2020 21:22
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class PayResultLandActivity extends BaseActivity<PayResultPresenter> implements PayResultContract.View {

    @BindView(R.id.tv1)
    TextView tv1;
    @BindView(R.id.tv2)
    TextView tv2;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {

        return R.layout.activity_pay_result_land; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    private void init_page() {
        SPUtils.getInstance().put(Constants.sp_page_value, "3");
    }

    @Override
    protected void onResume() {
        super.onResume();
        init_page();
    }

    int now_time = 8000;

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        init_page();
        String json = getIntent().getStringExtra("json");
        Order order = new Gson().fromJson(json, Order.class);
//        Order order = new Order();
//        order.order_id = "dsafadfsad";
//        order.audio_type = "3";
//        order.money = "777";
//        if (order == null) {
//            return;
//        }
        tv2.setText("￥" + order.money);
//        new SoundMaker(this).makeSound(order.audio_type, order.money);

        Runnable timeRunable = () -> {
            ActivityUtils.finishToActivity(GroupListActivity.class, false);
//            Intent intent = new Intent(PayResultActivity.this, GroupListActivity.class);
//            startActivity(intent);
//            killMyself();
        };
        mhandle.postDelayed(new Runnable() {
            @Override
            public void run() {
                VoicePlay.with(getApplicationContext()).play(order.order_id + "," + order.money, true);
            }
        }, 1000);
        mhandle.postDelayed(timeRunable, now_time);
    }

    //计时器
    private Handler mhandle = new Handler();
    private boolean isPause = false;//是否暂停
    public long currentSecond = 0;//当前毫秒数

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

}
